[PATCH] Apache2::SizeLimit aborts when smaps is not available

[PATCH] Apache2::SizeLimit aborts when smaps is not available

am 30.11.2009 22:44:47 von Harry Danilevsky

--0015174762a4e5a04204799d8c3f
Content-Type: text/plain; charset=ISO-8859-1

1. Problem Description:

Apache2::SizeLimit aborts when smaps facility is unavailable. Here's the
error from the error log:

Linux::Smaps: Cannot open /proc/9700/smaps: No such file or directory
BEGIN failed--compilation aborted at
/data/wre/prereqs/lib/perl5/site_perl/5.10.0/i686-linux/Apac he2/SizeLimit.pm
line 98

This installation is part of WebGUI CMS (hence the path, starting with
/data/wre),
but there's nothing specific to WebGUI here - it's just a plain mod_perl
file tree.

The error is not caused by insufficient read permissions - there are
simply no smaps files in /proc/xxx.
Apache2::SizeLimit documentation mentions two possible solutions:

1. Installing an OS patch with smaps support (which may or may not be an
option)

2. Setting $Apache2::SizeLimit::USE_SMAPS to 0 before the first check.
This doesn't
help in this particular case, because the error is generated within
the BEGIN block;
besides, the chunk of code which produces this error, pays no
attention to $USE_SMAPS


I believe the error is caused simply by placing the wrong (or rather
insufficient) statement inside eval() :

if ( eval { require Linux::Smaps } and Linux::Smaps->new($$) ) {
...
}

Linux::Smaps module is present, and obviously returns 1, but
Linux::Smaps->new throws an error
which is not being caught by eval.

I propose the following trivial patch:


--------------------------8<--------------------

*** ./SizeLimit.pm 2009-11-30 09:13:16.000000000 -0600
--- /tmp/SizeLimit.pm.orig 2009-11-30 09:24:04.000000000 -0600
***************
*** 58,64 ****

}
elsif (LINUX) {
! if ( eval { require Linux::Smaps and Linux::Smaps->new($$) } ) {
$HOW_BIG_IS_IT = \&linux_smaps_size_check_first_time;
}
else {
--- 58,64 ----

}
elsif (LINUX) {
! if ( eval { require Linux::Smaps } and Linux::Smaps->new($$) ) {
$HOW_BIG_IS_IT = \&linux_smaps_size_check_first_time;
}
else {

--------------------------8<--------------------


-- Harry Danilevsky

harry.danilevsky@gmail.com


2. Used Components and their Configuration:

*** mod_perl version 2.000004

*** using
/data/wre/prereqs/lib/perl5/site_perl/5.10.0/i686-linux/Apac he2/BuildConfig.pm

*** Makefile.PL options:
MP_APR_LIB => aprext
MP_APXS => /data/wre/prereqs/bin/apxs
MP_COMPAT_1X => 1
MP_GENERATE_XS => 1
MP_LIBNAME => mod_perl
MP_USE_DSO => 1


*** The httpd binary was not found


*** (apr|apu)-config linking info

-L/data/wre/prereqs/lib -laprutil-1 -lexpat
-L/data/wre/prereqs/lib -lapr-1 -lrt -lcrypt -lpthread -ldl



*** /data/wre/prereqs/bin/perl -V
Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
Platform:
osname=linux, osvers=2.4.21-51.el, archname=i686-linux
uname='linux centos3 2.4.21-51.el #1 thu aug 16 17:03:59 edt 2007 i686
i686 i386 gnulinux '
config_args='-Dprefix=/data/wre/prereqs -des'
hint=recommended, useposix=true, d_sigaction=define
useithreads=undef, usemultiplicity=undef
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-fno-strict-aliasing -pipe -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags='-fno-strict-aliasing -pipe -I/usr/local/include'
ccversion='', gccversion='3.2.3 20030502 (Red Hat Linux 3.2.3-59)',
gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldl -lm -lcrypt -lutil -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
libc=/lib/libc-2.3.2.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.3.2'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib'


Characteristics of this binary (from libperl):
Compile-time options: PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP
USE_LARGE_FILES USE_PERLIO
Built under linux
Compiled at May 27 2009 20:31:04
%ENV:
PERL_LWP_USE_HTTP_10="1"
@INC:
/data/wre/prereqs/lib/perl5/5.10.0/i686-linux
/data/wre/prereqs/lib/perl5/5.10.0
/data/wre/prereqs/lib/perl5/site_perl/5.10.0/i686-linux
/data/wre/prereqs/lib/perl5/site_perl/5.10.0
.

*** Packages of interest status:

Apache2 : -
Apache2::Request : 2.08
CGI : 3.42
ExtUtils::MakeMaker: 6.48
LWP : 5.824
mod_perl : -
mod_perl2 : 2.000004


3. This is the core dump trace: (if you get a core dump):



This report was generated by bin/mp2bug on Mon Nov 30 17:25:35 2009 GMT.

--0015174762a4e5a04204799d8c3f
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

1. Problem Description:

=A0 Apache2::SizeLimit aborts when smaps fac=
ility is unavailable. Here's the error from the error log:

Linux=
::Smaps: Cannot open /proc/9700/smaps: No such file or directory
BEGIN f=
ailed--compilation aborted at /data/wre/prereqs/lib/perl5/site_perl/5.10.0/=
i686-linux/Apache2/SizeLimit.pm line 98


This installation is part of WebGUI CMS (hence the path, starting with =
/data/wre),
but there's nothing specific to WebGUI here - it's j=
ust a plain mod_perl file tree.

The error is not caused by insuffici=
ent read permissions - there are

simply no smaps files in /proc/xxx.
Apache2::SizeLimit documentation men=
tions two possible solutions:
=A0
   1. Installing an OS patch wi=
th smaps support (which may or may not be an option)

   2. Setti=
ng $Apache2::SizeLimit::USE_SMAPS to 0 before the first check. This doesn&#=
39;t

    =A0 help in this particular case, because the error is generate=
d within the BEGIN block;
    =A0 besides, the chunk of code whi=
ch produces this error, pays no attention to $USE_SMAPS


I believ=
e the error is caused simply by placing the wrong (or rather insufficient) =
statement inside eval() :


      =A0 if ( eval { require Linux::Smaps } and Linux::Sma=
ps->new($$) ) {
             ...
  =A0=
     }

Linux::Smaps module is present, and obviously returns=
1, but Linux::Smaps->new throws an error

which is not being caught by eval.

I propose the following trivial p=
atch:


--------------------------8<--------------------
>*** ./SizeLimit.pm    =A0 2009-11-30 09:13:16.000000000 -0600
-=
-- /tmp/SizeLimit.pm.orig    =A0 2009-11-30 09:24:04.000000000 -060=
0

***************
*** 58,64 ****
=A0
    =A0 }
  =A0=
   elsif (LINUX) {
!         if ( eval { require Lin=
ux::Smaps and Linux::Smaps->new($$) } ) {
        =A0=
     $HOW_BIG_IS_IT =3D \&linux_smaps_size_check_first_time; >
        =A0 }
        =A0 else {
--- =
58,64 ----
=A0
    =A0 }
    =A0 elsif (LINUX) {<=
br>!         if ( eval { require Linux::Smaps } and Linux::=
Smaps->new($$) ) {
            =A0 $HOW_BIG_I=
S_IT =3D \&linux_smaps_size_check_first_time;

        =A0 }
        =A0 else {

=
--------------------------8<--------------------


-- Harry Dan=
ilevsky

harry.danilevs=
ky@gmail.com



2. Used Components and their Configuration:


*** mod_perl version 2.000004

*** using /data/wre/prereqs/lib/pe=
rl5/site_perl/5.10.0/i686-linux/Apache2/BuildConfig.pm

*** Makefile.=
PL options:
=A0 MP_APR_LIB     =3D> aprext
=A0 MP_APXS=A0=
       =3D> /data/wre/prereqs/bin/apxs

=A0 MP_COMPAT_1X   =3D> 1
=A0 MP_GENERATE_XS =3D> 1
=A0 MP_=
LIBNAME     =3D> mod_perl
=A0 MP_USE_DSO     =3D> =
1


*** The httpd binary was not found


*** (apr|apu)-co=
nfig linking info

=A0-L/data/wre/prereqs/lib -laprutil-1=A0 -lexpat =


=A0-L/data/wre/prereqs/lib -lapr-1 -lrt -lcrypt=A0 -lpthread -ldl

<=
br>
*** /data/wre/prereqs/bin/perl -V
Summary of my perl5 (revision 5=
version 10 subversion 0) configuration:
=A0 Platform:
  =A0 osna=
me=3Dlinux, osvers=3D2.4.21-51.el, archname=3Di686-linux

  =A0 uname=3D'linux centos3 2.4.21-51.el #1 thu aug 16 17:03:59 ed=
t 2007 i686 i686 i386 gnulinux '
  =A0 config_args=3D'-Dpref=
ix=3D/data/wre/prereqs -des'
  =A0 hint=3Drecommended, useposix=
=3Dtrue, d_sigaction=3Ddefine

  =A0 useithreads=3Dundef, usemultiplicity=3Dundef
  =A0 useperl=
io=3Ddefine, d_sfio=3Dundef, uselargefiles=3Ddefine, usesocks=3Dundef
=
  =A0 use64bitint=3Dundef, use64bitall=3Dundef, uselongdouble=3Dundef r>  =A0 usemymalloc=3Dn, bincompat5005=3Dundef

=A0 Compiler:
  =A0 cc=3D'cc', ccflags =3D'-fno-strict-a=
liasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=
=3D64',
  =A0 optimize=3D'-O2',
  =A0 cppflags=3D=
'-fno-strict-aliasing -pipe -I/usr/local/include'

  =A0 ccversion=3D'', gccversion=3D'3.2.3 20030502 (Red Hat=
Linux 3.2.3-59)', gccosandvers=3D''
  =A0 intsize=3D4, =
longsize=3D4, ptrsize=3D4, doublesize=3D8, byteorder=3D1234
  =A0 d_=
longlong=3Ddefine, longlongsize=3D8, d_longdbl=3Ddefine, longdblsize=3D12 r>
  =A0 ivtype=3D'long', ivsize=3D4, nvtype=3D'double', n=
vsize=3D8, Off_t=3D'off_t', lseeksize=3D8
  =A0 alignbytes=
=3D4, prototype=3Ddefine
=A0 Linker and Libraries:
  =A0 ld=3D=
9;cc', ldflags =3D' -L/usr/local/lib'

  =A0 libpth=3D/usr/local/lib /lib /usr/lib
  =A0 libs=3D-lnsl -=
ldl -lm -lcrypt -lutil -lc
  =A0 perllibs=3D-lnsl -ldl -lm -lcrypt -=
lutil -lc
  =A0 libc=3D/lib/libc-2.=
3.2.so
, so=3Dso, useshrplib=3Dfalse, libperl=3Dlibperl.a

  =A0 gnulibc_version=3D'2.3.2'
=A0 Dynamic Linking:
=A0=
   dlsrc=3Ddl_dlopen.xs, dlext=3Dso, d_dlsymun=3Dundef, ccdlflags=3D=
9;-Wl,-E'
  =A0 cccdlflags=3D'-fPIC', lddlflags=3D'-=
shared -O2 -L/usr/local/lib'



Characteristics of this binary (from libperl):
=A0 Compile-time=
options: PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP
      =A0=
                 USE_LARGE_FILES USE_PERLIO=

=A0 Built under linux
=A0 Compiled at May 27 2009 20:31:04

=A0 %ENV:
  =A0 PERL_LWP_USE_HTTP_10=3D"1"
=A0 @INC: >  =A0 /data/wre/prereqs/lib/perl5/5.10.0/i686-linux
  =A0 /data=
/wre/prereqs/lib/perl5/5.10.0
  =A0 /data/wre/prereqs/lib/perl5/site=
_perl/5.10.0/i686-linux

  =A0 /data/wre/prereqs/lib/perl5/site_perl/5.10.0
  =A0 .
r>*** Packages of interest status:

Apache2        =
  =A0 : -
Apache2::Request   : 2.08
CGI      =A0=
         : 3.42
ExtUtils::MakeMaker: 6.48
LWP  =
            =A0 : 5.824

mod_perl           : -
mod_perl2      =
  =A0 : 2.000004


3. This is the core dump trace: (if you get=
a core dump):

=A0

This report was generated by bin/mp2bug o=
n Mon Nov 30 17:25:35 2009 GMT.







--0015174762a4e5a04204799d8c3f--